load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "index_catalog_mock",
    deps = [
    ],
)

mongo_cc_library(
    name = "cannot_convert_index_to_unique_info",
    srcs = [
        "cannot_convert_index_to_unique_info.cpp",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

idl_generator(
    name = "collection_options_gen",
    src = "collection_options.idl",
    hdrs = [
        "collection_options_validation.h",
    ],
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "clustered_collection_options_gen",
    src = "clustered_collection_options.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "collection_options",
    srcs = [
        "clustered_collection_options_gen",
        "clustered_collection_util.cpp",
        "collection_options.cpp",
        "collection_options_gen",
        "collection_options_validation.cpp",
    ],
    deps = [
        "//src/mongo/crypto:encrypted_field_config",
        "//src/mongo/db:common",
        "//src/mongo/db:server_base",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/db/pipeline:change_stream_pre_and_post_images_options",
        "//src/mongo/db/query:query_knobs",
        "//src/mongo/db/query/collation:collator_interface",
        "//src/mongo/db/query/query_shape",
        "//src/mongo/db/timeseries:timeseries_options",
    ],
)

mongo_cc_library(
    name = "durable_catalog",
    srcs = [
        "durable_catalog.cpp",
    ],
    deps = [
        ":collection_record_store_options",
        ":durable_catalog_entry_metadata",
        "//src/mongo/db:server_base",
        "//src/mongo/db/op_observer:op_observer_util",
        "//src/mongo/db/rss:replicated_storage_service",
        "//src/mongo/db/storage:feature_document_util",
        "//src/mongo/db/storage:ident",
        "//src/mongo/db/storage:mdb_catalog",
        "//src/mongo/db/storage:record_store_base",
    ],
)

mongo_cc_library(
    name = "durable_catalog_entry_metadata",
    srcs = [
        "durable_catalog_entry_metadata.cpp",
    ],
    deps = [
        ":collection_options",
        "//src/mongo/db:common",
        "//src/mongo/db/index:multikey_paths",
    ],
)

mongo_cc_library(
    name = "collection_catalog",
    srcs = [
        "collection_catalog.cpp",
        "historical_catalogid_tracker.cpp",
        "uncommitted_catalog_updates.cpp",
        "uncommitted_multikey.cpp",
        "views_for_database.cpp",
    ],
    deps = [
        ":durable_catalog",
        ":durable_catalog_entry_metadata",
        "//src/mongo/db:audit",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/query/collation:collator_factory_interface",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/shard_role:shard_role_api_stor_ex",
        "//src/mongo/db/storage:mdb_catalog",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/views",
    ],
)

mongo_cc_library(
    name = "collection_uuid_mismatch_info",
    srcs = [
        "collection_uuid_mismatch_info.cpp",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "index_catalog",
    srcs = [
        "index_catalog.cpp",
        "index_catalog_entry.cpp",
    ],
    deps = [
        "//src/mongo/crypto:fle_fields",
        "//src/mongo/db:server_base",
        "//src/mongo/db/shard_role:shard_role_api_stor_ex",
        "//src/mongo/db/storage:storage_options",
    ],
)

mongo_cc_library(
    name = "database_holder",
    srcs = [
        "database_holder.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

mongo_cc_library(
    name = "database_holder_mock",
    deps = [
        ":database_holder",
    ],
)

mongo_cc_library(
    name = "document_validation",
    srcs = [
        "document_validation.cpp",
    ],
    deps = [
        "//src/mongo/db:service_context",
    ],
)

mongo_cc_library(
    name = "catalog_stats",
    srcs = [
        "catalog_stats.cpp",
    ],
    deps = [
        ":collection_catalog",
        ":database_holder",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/views",
    ],
)

mongo_cc_library(
    name = "catalog_repair",
    srcs = [
        "catalog_repair.cpp",
    ],
    deps = [
        ":durable_catalog",
        "//src/mongo/db:server_base",
        "//src/mongo/db/storage:mdb_catalog",
        "//src/mongo/db/storage:storage_engine_impl",
    ],
)

mongo_cc_library(
    name = "catalog_helpers",
    srcs = [
        "backwards_compatible_collection_options_util.cpp",
        "coll_mod.cpp",
        "coll_mod_index.cpp",
        "collection_catalog_helper.cpp",
        "create_collection.cpp",
        "drop_collection.cpp",
        "drop_database.cpp",
        "drop_indexes.cpp",
        "external_data_source_scope_guard.cpp",
        "list_indexes.cpp",
        "rename_collection.cpp",
        "unique_collection_name.cpp",
        "//src/mongo/db:collection_compact.cpp",
        "//src/mongo/db/collection_crud:capped_utils.cpp",
    ],
    deps = [
        ":cannot_convert_index_to_unique_info",
        ":collection_options",
        ":collection_uuid_mismatch_info",
        ":document_validation",
        ":index_catalog",
        "//src/mongo:base",
        "//src/mongo/db:audit",
        "//src/mongo/db:index_key_validate",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:throttle_cursor",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/index_builds:multi_index_block",
        "//src/mongo/db/query/write_ops",
        "//src/mongo/db/repl:local_oplog_info",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/ddl:coll_mod_command_idl",
        "//src/mongo/db/shard_role/ddl:index_commands_idl",
        "//src/mongo/db/shard_role/ddl:server_parameters_idl",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/stats:top",
        "//src/mongo/db/storage:index_entry_comparison",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/db/storage:storage_engine_common",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/db/timeseries:catalog_helper",
        "//src/mongo/db/timeseries:collection_pre_conditions_util",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/timeseries:viewless_timeseries_collection_creation_helpers",
        "//src/mongo/db/ttl:ttl_collection_cache",
        "//src/mongo/db/validate:validate_idl",
        "//src/mongo/db/views",
        "//src/mongo/db/views:view_catalog_helpers",
    ],
)

mongo_cc_library(
    name = "catalog_control",
    srcs = [
        "catalog_control.cpp",
    ],
    deps = [
        ":catalog_repair",
        ":catalog_stats",
        ":collection_catalog",
        ":collection_record_store_options",
        ":database_holder",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/db/storage:write_unit_of_work",
        "//src/mongo/db/timeseries:timeseries_extended_range",
    ],
)

mongo_cc_library(
    name = "collection_record_store_options",
    srcs = [
        "collection_record_store_options.cpp",
    ],
    deps = [
        ":collection_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db/storage:record_store_base",
    ],
)

mongo_cc_library(
    name = "catalog_impl",
    srcs = [
        "collection_impl.cpp",
        "database_holder_impl.cpp",
        "database_impl.cpp",
        "index_catalog_entry_helpers.cpp",
        "index_catalog_entry_impl.cpp",
        "index_catalog_impl.cpp",
        "virtual_collection_impl.cpp",
    ],
    deps = [
        "catalog_helpers",
        "catalog_stats",
        "collection_options",
        "document_validation",
        "durable_catalog",
        "index_catalog",
        "//src/mongo/db:audit",
        "//src/mongo/db:collection_index_usage_tracker",
        "//src/mongo/db:dbcommands_idl",
        "//src/mongo/db:fle_implicit_validator",
        "//src/mongo/db:index_key_validate",
        "//src/mongo/db:index_repair",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db:system_index",
        "//src/mongo/db:throttle_cursor",
        "//src/mongo/db:vector_clock",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/index:preallocated_container_pool",
        "//src/mongo/db/matcher/doc_validation",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/query/virtual_collection",
        "//src/mongo/db/repl:local_oplog_info",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:repl_server_parameters",
        "//src/mongo/db/repl:repl_settings",
        "//src/mongo/db/repl/dbcheck:health_log_interface",
        "//src/mongo/db/rss:replicated_storage_service",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/stats:top",
        "//src/mongo/db/storage:mdb_catalog",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/db/storage:storage_engine_common",
        "//src/mongo/db/storage:storage_engine_impl",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_extended_range",
        "//src/mongo/db/timeseries:viewless_timeseries_collection_creation_helpers",
        "//src/mongo/db/transaction",
        "//src/mongo/db/ttl:ttl_collection_cache",
        "//src/mongo/db/validate:validate_idl",
        "//src/mongo/db/validate:validate_state",
        "//src/mongo/db/views:view_catalog_helpers",
        "//src/mongo/util:log_and_backoff",
        "//src/mongo/util:progress_meter",
    ],
)

mongo_cc_library(
    name = "snapshot_helper",
    srcs = [
        "snapshot_helper.cpp",
    ],
    deps = [
        "//src/mongo/db/repl:read_concern_args",
        "//src/mongo/db/repl:repl_coordinator_interface",
    ],
)

mongo_cc_library(
    name = "catalog_test_fixture",
    srcs = [
        "catalog_test_fixture.cpp",
    ],
    deps = [
        ":catalog_helpers",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
    ],
)

mongo_cc_library(
    name = "collection_mock",
    deps = [":collection_options"],
)

mongo_cc_benchmark(
    name = "collection_catalog_bm",
    srcs = [
        "collection_catalog_bm.cpp",
    ],
    deps = [
        ":collection_catalog",
        ":collection_mock",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/db/shard_role/lock_manager",
    ],
)

mongo_cc_unit_test(
    name = "db_catalog_test",
    srcs = [
        "backwards_compatible_collection_options_util_test.cpp",
        "coll_mod_test.cpp",
        "collection_catalog_test.cpp",
        "collection_options_test.cpp",
        "collection_test.cpp",
        "collection_writer_test.cpp",
        "create_collection_test.cpp",
        "database_test.cpp",
        "drop_database_test.cpp",
        "historical_catalogid_tracker_test.cpp",
        "index_catalog_entry_impl_test.cpp",
        "index_catalog_impl_test.cpp",
        "index_signature_test.cpp",
        "rename_collection_test.cpp",
    ],
    tags = ["mongo_unittest_eighth_group"],
    deps = [
        ":catalog_control",
        ":catalog_helpers",
        ":catalog_impl",
        ":catalog_test_fixture",
        ":collection_catalog",
        ":collection_mock",
        ":collection_options",
        ":database_holder",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:index_key_validate",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db:throttle_cursor",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/index_builds:commit_quorum_options",
        "//src/mongo/db/index_builds:index_build_block",
        "//src/mongo/db/index_builds:index_build_entry_idl",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/index_builds:index_builds_coordinator_mongod",
        "//src/mongo/db/index_builds:multi_index_block",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/op_observer:op_observer_impl",
        "//src/mongo/db/op_observer:operation_logger_impl",
        "//src/mongo/db/op_observer:operation_logger_mock",
        "//src/mongo/db/query/datetime:date_time_support",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:oplog_application",
        "//src/mongo/db/repl:optime",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/ddl:coll_mod_command_idl",
        "//src/mongo/db/shard_role/ddl:index_commands_idl",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/timeseries:timeseries_collmod",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/validate:collection_validation",
        "//src/mongo/db/validate:validate_idl",
        "//src/mongo/db/validate:validate_state",
        "//src/mongo/unittest",
        "//src/mongo/util:clock_source_mock",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_unit_test(
    name = "index_validate_test",
    srcs = [
        "//src/mongo/db:index_key_validate_test.cpp",
        "//src/mongo/db:index_spec_validate_test.cpp",
    ],
    tags = [
        "mongo_unittest_seventh_group",
        "server-index-builds",
    ],
    deps = [
        "//src/mongo/db:index_key_validate",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/query/collation:collator_factory_mock",
        "//src/mongo/db/query/collation:collator_interface_mock",
        "//src/mongo/unittest",
    ],
)

mongo_cc_unit_test(
    name = "throttle_cursor_test",
    srcs = [
        "//src/mongo/db:throttle_cursor_test.cpp",
    ],
    tags = [
        "mongo_unittest_seventh_group",
        "server-integration-smoke",
    ],
    deps = [
        ":catalog_control",
        ":catalog_helpers",
        ":catalog_impl",
        ":catalog_test_fixture",
        ":collection_catalog",
        ":collection_mock",
        ":collection_options",
        "//src/mongo/db:index_key_validate",
        "//src/mongo/db:throttle_cursor",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:oplog_application",
        "//src/mongo/db/repl:optime",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/validate:collection_validation",
        "//src/mongo/db/validate:validate_idl",
        "//src/mongo/db/validate:validate_state",
        "//src/mongo/unittest",
        "//src/mongo/util:clock_source_mock",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_unit_test(
    name = "collection_record_store_options_test",
    srcs = [
        "collection_record_store_options_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":collection_record_store_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/unittest",
    ],
)

mongo_cc_benchmark(
    name = "catalog_control_bm",
    srcs = [
        "catalog_control_bm.cpp",
    ],
    deps = [
        ":collection_catalog",
        ":collection_mock",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/shard_role/shard_catalog:catalog_control",
    ],
)

idl_generator(
    name = "validate_db_metadata_gen",
    src = "validate_db_metadata.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "validate_db_metadata_command",
    srcs = [
        ":validate_db_metadata_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

idl_generator(
    name = "shard_authoritative_catalog_gen",
    src = "shard_authoritative_catalog.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "type_oplog_catalog_metadata_gen",
    src = "type_oplog_catalog_metadata.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/global_catalog:type_database_gen",
    ],
)

idl_generator(
    name = "collection_critical_section_document_gen",
    src = "collection_critical_section_document.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "participant_block_gen",
    src = "participant_block.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "flush_database_cache_updates_gen",
    src = "flush_database_cache_updates.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "flush_routing_table_cache_updates_gen",
    src = "flush_routing_table_cache_updates.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "raw_data_operation",
    srcs = [
        "raw_data_operation.cpp",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)
